package com.icinema.server;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CommonUtils implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -8530544885611913597L;


	private static String translate(String number){
		char[] cArray= number.toCharArray();
		StringBuffer buf = new StringBuffer();
		for(int i=0;i<cArray.length;i++){
			buf.append(getChar(cArray[i]));
		}
		return buf.toString();
	}
	public static String getDateString(Date date,String pattern){
		SimpleDateFormat dateFormat = new SimpleDateFormat();
		dateFormat.applyPattern(pattern);
		return dateFormat.format(date);
		
	}
	//must be in Nov 11, 2010 12:00:00 AM format
	public static String getBurmeseDate(String englishDate){
		if(englishDate.equals("")) return "";
		SimpleDateFormat format = new SimpleDateFormat("MMM d, yyyy hh:mm:ss a");
		Date outDate = new Date();;
		String outStr = "";
		try {
			outDate = format.parse(englishDate);
			outStr = getDateString(outDate,"dd-MM-yyyy");
		} catch (ParseException e) {
			
			e.printStackTrace();
		}
		String[] str = outStr.split("-");
		return translate(str[0])+"."+translate(str[1])+"."+translate(str[2]);
	}
	public static Date getDate(String stringDate){
		if(stringDate.equals("")) return new Date();
		SimpleDateFormat format = new SimpleDateFormat("MMM d, yyyy hh:mm:ss a");
		Date outDate = new Date();;
		try {
			outDate = format.parse(stringDate);
		} catch (ParseException e) {
		}

		return outDate;
	}	
	
	
	private static char getChar(char c){
		char ret = 0;
		if(c == '0' ){
			ret = 0x1040 ;
		}
		if(c == '1'){
			ret = 0x1041;
		}
		if(c == '2'){
			ret = 0x1042;
		}
		if(c == '3'){
			ret = 0x1043;
		}
		if(c == '4'){
			ret = 0x1044;
		}
		if(c=='5'){
			ret = 0x1045;
		}
		if(c=='6'){
			ret = 0x1046;
		}
		if(c=='7'){
			ret = 0x1047;
		}
		if(c=='8'){
			ret = 0x1048;
		}
		if(c=='9'){
			ret = 0x1049;
		}
		return ret;
	}
	
}
